package com.swpu.zdl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.swpu.zdl.mapper.JieYueMapper;
import com.swpu.zdl.mapper.UserMapper;
import com.swpu.zdl.pojo.JieYue;
import com.swpu.zdl.pojo.User;
import com.swpu.zdl.service.JieYueService;
import com.swpu.zdl.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Service
public class JieYueServiceImpl extends ServiceImpl<JieYueMapper, JieYue> implements JieYueService {
    @Autowired
    private JieYueMapper jieYueMapper;

    @Override
    public void SetJieYue(JieYue jieYue) {
        jieYue.setReTime("");
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String formattedDateTime = now.format(formatter);
        jieYue.setGetTime(formattedDateTime);
        jieYue.setJieStatus("已借阅");
        LambdaQueryWrapper<JieYue> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(JieYue::getId, jieYue.getId());
        jieYueMapper.update(jieYue, lambdaQueryWrapper);
    }

    @Override
    public void GuiHuan(JieYue jieYue) {
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String formattedDateTime = now.format(formatter);
        jieYue.setReTime(formattedDateTime);
        jieYue.setJieStatus("待借阅");
        LambdaQueryWrapper<JieYue> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(JieYue::getId, jieYue.getId());
        jieYueMapper.update(jieYue, lambdaQueryWrapper);
    }
}
